<?php

namespace app\Admin\model;

use think\Model;
use think\Db;

class Do_login extends Model
{
    public function index($data)
    {
        $username = $data['Name'];
        $password = $data['Password'];
        $role = $data['Role'];

        //根据角色对应不同查询操作
        if($role == 'student')
        {
            $result = Db::table('student')->where('User_name',$username)->find();
        } else {
            $result = Db::table('teacher')->where('User_name',$username)->find();
        }
        //不同用户登录页面不同
        if ($result) {
            if ($result['User_password'] == $password) {
                session('Name', $username);
                session('role',$role);
                return ($role=='student')?4:3; //信息正确
            } else {
                // var_dump($user);
                // var_dump($data);
                return 2; //密码错误
            }
        } else {
            return 1; //用户不存在
        }
    }
}

?>